package worklog.dto;

import java.util.TreeMap;

import worklog.DaysCalculator;

import com.google.gson.Gson;

public class ProjectActivityDTO extends ProjectDTO {
	private TreeMap<String, Integer> rows;
	private long[][] chartData;

	public TreeMap<String, Integer> getRows() {
		return rows;
	}

	public void setRows(TreeMap<String, Integer>  rows) {
		this.rows = rows;
		this.processChartData();
	}
	
	public long[][] getChartData() {
		return chartData;
	}

	public void setChartData(long[][] chartData) {
		this.chartData = chartData;
	}	
	
	private void processChartData(){
		TreeMap<String, Integer> rows = this.getRows();
    	String[] days = DaysCalculator.getDays(rows.firstKey(), rows.lastKey());
    	int i = 0, il = days.length;
    	long[][] data = new long[il][2];
    	
    	for (; i < il; i++){
    		String day = days[i];
    		long val = 0;
    		if (rows.get(day) != null) val = (long)rows.get(day); 
    		long[] row = {DaysCalculator.strToTime(day), val};
    		data[i] = row;
    	}
    	this.setChartData(data);
	}
	

	public String toString() {
		this.rows = null;
		return new Gson().toJson(this);		
	}

}

